<?php

//session
session_start();
if(isset($_SESSION['usr_name'])!="") {
	header("Location: index.php");
}

include_once '../sql/dbconnect.php';

//check if form is submitted
if (isset($_POST['login'])) {
	$phone = mysqli_real_escape_string($con, $_POST['phone']);
	$password = mysqli_real_escape_string($con, $_POST['password']);
	$result = mysqli_query($con, "SELECT * FROM userinfo WHERE phone = '" . $phone. "' and password = '" . md5($password) . "'");

	if ($row = mysqli_fetch_array($result)) {
		$_SESSION['usr_name'] = $row['phone'];
		$successmsg = "登录成功~";
		header("Location: index.php");
	} else {
		$errormsg = "请确认用户名或密码！";
	}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>用户登录页面</title>
	<link rel="stylesheet" type="text/css" href="../css/index.css">
	<link rel="stylesheet" type="text/css" href="../css/common.css">
	<link rel="shortcut icon" href="http://ucenter.b5m.com/favicon.ico?_=" type="image/x-ion">
	<script type="text/javascript" src="../js/jQuery.js"></script>
	<script type="text/javascript" src="../js/template.js"></script>
	<script type="text/javascript" src="../js/index.js"></script>
	<script type="text/javascript" src="../js/cookie.js"></script>
</head>
<body>
	<div id="main_enter" class="common overHidden minWidth">
		<div class="logo margin_auto"><a href="javascript:;"><img src="../img/logo1.png"></a></div>
		<h2 class="margin_auto">MyWay，畅享全球品质生活！</h2>
		<div class="toast-msg margin_auto"><?php if (isset($successmsg)) { echo $successmsg; }; if (isset($errormsg)) { echo $errormsg; };?></div>
		<p class="margin_auto">使用MyWay账户登录</p>
		<div class="form_check margin_auto">
			<form method="post" active="<?php echo $_SERVER['PHP_SELF']; ?>" onsubmit="return disabledSub();">
				<ul>
					<li class="txtLi">
						<input type="text" class="txt" placeholder="邮箱/手机" name="phone">
						<p class="txtW">请输入邮箱/手机!</p>
					</li>
					<li class="psdLi">
						<input type="password" class="psd" placeholder="密码" name="password">
						<p class="psdW1">密码不能为空!</p>
						<p class="psdW2">密码长度介于6和15之间!</p>
					</li>
					<li class="vcLi">
						<input type="text" class="vc_text" name="" placeholder="请输入验证码">
						<p class="vc_code right">
							<b class="code_show"></b>
							<span class="code_reset"><a href="javascript:;">点击<br>换一换</a></span>
						</p>
						<p class="vc_war">验证码错误！</p>
					</li>
					<li class="forget_link">
						<p class="fast_login left">
							使用其他账号登录 :　
							<a class="qq" href="javascript:;"></a>
							<a class="wx" href="javascript:;"></a>
							<a class="wb" href="javascript:;"></a>
						</p>
						<span class="forget right">
							忘记密码？
							<span class="detail">
								<a href="javascript:;">手机账号</a>　
								<a href="javascript:;">邮箱账号</a>
							</span>
						</span>
					</li>
					<li class="login">
						<input class="submit" type="submit" name="login" value="登　录">
					</li>
					<li class="reg">
						<a href="login.php">注册</a>
					</li>
				</ul>
			</form>
		</div>
	</div>
	<script type="text/javascript">
		var inpVc = $("#main_enter .vc_text"),
			codeShow = $(".common .code_show");
		//验证码错误阻止提交
		function disabledSub(event){
			if(inpVc.val().toLowerCase() != codeShow.text().toLowerCase()){
				$('.submit').focus();
				var event = event || window.event;
				event.preventDefault(); // 兼容标准浏览器
  				window.event.returnValue = false; // 兼容IE6~8
			}
		}
	</script>
</body>
</html>